import Vue from 'vue'
import Router from 'vue-router'
import {
  checkIsMobile
} from './utils/checkDevice'
import PCHome from './views/computer/Home/Home.vue'
import MHome from './views/mobile/Home/Home.vue'

const Home = checkIsMobile() ? MHome : PCHome
const type = checkIsMobile() ? 'mobile' : 'computer'

Vue.use(Router)

let router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [{
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      component: Home
    },
    {
      path: '/token',
      component: () => import(`./views/${type}/Token/Token.vue`)
    },
    {
      path: '/mainHolder',
      component: () => import(`./views/${type}/Holder/MainHolder.vue`)
    },
    {
      path: '/block',
      component: () => import(`./views/${type}/Block/Block.vue`)
    },
    {
      path: '/address',
      component: () => import(`./views/${type}/Address/Address.vue`)
    },
    {
      path: '/blockdetail',
      component: () => import(`./views/${type}/BlockDetail/BlockDetail.vue`)
    },
    {
      path: '/node',
      component: () => import(`./views/${type}/Nodes/Nodes.vue`)
    },
    {
      path: '/tokenDetail',
      component: () => import(`./views/${type}/TokenDetail/TokenDetail.vue`)
    },
    {
      path: '/broadtx',
      component: () => import(`./views/${type}/Tool/BroadCast.vue`)
    },
    {
      path: '/alytx',
      component: () => import(`./views/${type}/Tool/Anylise.vue`)
    },
    {
      path: '/tradelist',
      component: () => import(`./views/${type}/Trade/Trade.vue`)
    },
    {
      path: '/tradeHash',
      component: () => import(`./views/${type}/TradeDetail/TradeDetail.vue`)
    },
    {
      path: '/holder',
      component: () => import(`./views/${type}/Holder/Holder.vue`)
    },
    {
      path: '*',
      redirect: '/'
    }
  ]
})

router.afterEach((old, newRoute) => {
  if (newRoute.query && newRoute.query.adr && newRoute.query.adr !== '')
    window.scrollTo(0, 0)
})

export default router